package com.yyw.util;

import javax.servlet.http.HttpSession;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.yyw.bean.User;

/**
 * 获取上下文对象的组件
 *
 * <p>
 * Title: MyContext
 * </p>
 *
 * <p>
 * Description:
 * </p>
 *
 * @author 8852LDS
 *
 * @date 2020年5月4日
 */
public class MyContext {

    /**
     * 获取session
     *
     * @return
     */
    public static HttpSession getHttpSession() {
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpSession session = attributes.getRequest().getSession();
        return session;
    }

    public static User getSessionUser() {
        return (User) getHttpSession().getAttribute("user") ;
    }
}
